package tx.bjdacp.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.org.rapid_framework.beanutils.BeanUtils;
import cn.org.rapid_framework.web.scope.Flash;

import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import tx.bjdacp.model.*;
import tx.bjdacp.dao.*;
import tx.bjdacp.service.*;
import tx.bjdacp.vo.query.*;


public class DrugSellUnitPrepareAction extends BaseStruts2Action implements Preparable,ModelDriven{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = "acceptDate asc";

	//forward paths
	protected static final String QUERY_JSP = "/pages/DrugSellUnitPrepare/query.jsp";
	protected static final String LIST_JSP= "/pages/DrugSellUnitPrepare/list.jsp";
	protected static final String CREATE_JSP = "/pages/DrugSellUnitPrepare/create.jsp";
	protected static final String EDIT_JSP = "/pages/DrugSellUnitPrepare/edit.jsp";
	protected static final String SHOW_JSP = "/pages/DrugSellUnitPrepare/show.jsp";
	//redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/pages/DrugSellUnitPrepare/list.do";

	private DrugSellUnitPrepareManager drugSellUnitPrepareManager;

	private DrugSellUnitPrepare drugSellUnitPrepare;
	java.lang.Integer id = null;
	private String[] items;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			drugSellUnitPrepare = new DrugSellUnitPrepare();
		} else {
			drugSellUnitPrepare = (DrugSellUnitPrepare)drugSellUnitPrepareManager.getById(id);
		}
	}

	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
	public void setDrugSellUnitPrepareManager(DrugSellUnitPrepareManager manager) {
		this.drugSellUnitPrepareManager = manager;
	}

	public Object getModel() {
		return drugSellUnitPrepare;
	}

	public void setDrugSellUnitPrepareId(java.lang.Integer val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}

	/** 执行搜索 */
	public String list() {
		DrugSellUnitPrepareQuery query = newQuery(DrugSellUnitPrepareQuery.class,DEFAULT_SORT_COLUMNS);

		Page page = drugSellUnitPrepareManager.findPage(query);
		savePage(page,query);
		return LIST_JSP;
	}

	/** 查看对象*/
	public String show() {
		return SHOW_JSP;
	}

	/** 进入新增页面*/
	public String create() {
		return CREATE_JSP;
	}
	private ZoneManager zoneManager;
	public void setZoneManager(ZoneManager manager) {
		this.zoneManager = manager;
	}

	/** 保存新增对象 */
	public String save() {
		drugSellUnitPrepare.setZoneName(zoneManager.getById(drugSellUnitPrepare.getZoneId()).getZoneName()+"镇");
		drugSellUnitPrepareManager.save(drugSellUnitPrepare);
		Flash.current().success(CREATED_SUCCESS); //存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息
		return LIST_ACTION;
	}

	/**进入更新页面*/
	public String edit() {
		return EDIT_JSP;
	}

	/**保存更新对象*/
	public String update() {
		drugSellUnitPrepare.setZoneName(zoneManager.getById(drugSellUnitPrepare.getZoneId()).getZoneName()+"镇");
		drugSellUnitPrepareManager.update(this.drugSellUnitPrepare);
		Flash.current().success(UPDATE_SUCCESS);
		return LIST_ACTION;
	}

	/**删除对象*/
	public String delete() {
		for(int i = 0; i < items.length; i++) {
			Hashtable params = HttpUtils.parseQueryString(items[i]);
			java.lang.Integer id = new java.lang.Integer((String)params.get("drugSellUnitPrepareId"));
			drugSellUnitPrepareManager.removeById(id);
		}
		Flash.current().success(DELETE_SUCCESS);
		return LIST_ACTION;
	}

}
